
package Presentacion;

import ModeloLogicoSistema.AdministradorCliente;
import ModeloLogicoSistema.Cliente;
import java.sql.SQLException;

/**
 *
 * @author Veko
 */
public class ModificacionCliente extends javax.swing.JDialog {
    AdministradorCliente admCliente = new  AdministradorCliente();
    Cliente cliente=null;
    
    public ModificacionCliente(java.awt.Frame parent, boolean modal,Cliente cliente) throws SQLException {

        super(parent, modal);
        this.cliente=cliente;
        this.setSize(325, 400);
        this.setResizable(false);
        
        AdministradorCliente admCliente = null;
        try {
            admCliente = new AdministradorCliente();
        } catch (SQLException ex) {

        }
        initComponents();
        this.setTitle("      Modificación De Cliente ");
        this.setLocationRelativeTo(null);
        this.setearFormulario();

    }
    
    private void setearFormulario(){
        //No olvidar tener en cuenta valores null
        
        Integer id=this.cliente.getNroCliente();
        String idCliente=id.toString();
        txtID.setText(idCliente);
        txtApellido.setText(cliente.getApellido());
        txtNombre.setText(cliente.getNombre());
        txtTel.setText(cliente.getTelFijo());
        txtCel.setText(cliente.getCel());
        txtLocalidad.setText(cliente.getLocalidad());
        txtCalle.setText(cliente.getCalle());
        txtCP.setText(cliente.getCP());
        txtPiso.setText(cliente.getPisoNro());
        txtCP.setText(cliente.getCP());
    }
    

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        txtApellido = new javax.swing.JTextField();
        txtPreCel = new javax.swing.JTextField();
        txtLocalidad = new javax.swing.JTextField();
        txtCalle = new javax.swing.JTextField();
        txtNumCalle = new javax.swing.JTextField();
        txtCP = new javax.swing.JTextField();
        BtnAceptar = new javax.swing.JButton();
        BtnCancelar = new javax.swing.JButton();
        txtCel = new javax.swing.JTextField();
        txtTel = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        txtPiso = new javax.swing.JTextField();
        txtNombre = new javax.swing.JTextField();

        setPreferredSize(new java.awt.Dimension(325, 400));
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jLabel1.setText("ID");
        getContentPane().add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 11, -1, -1));

        jLabel2.setText("Nombre");
        getContentPane().add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 40, -1, -1));

        jLabel3.setText("Apellido");
        getContentPane().add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 71, -1, -1));

        jLabel4.setText("Telefono");
        getContentPane().add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 102, -1, -1));

        jLabel5.setText("Celular");
        getContentPane().add(jLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 128, -1, -1));

        jLabel6.setText("Localidad");
        getContentPane().add(jLabel6, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 159, -1, -1));

        jLabel7.setText("Calle");
        getContentPane().add(jLabel7, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 190, -1, -1));

        jLabel8.setText("Numero");
        getContentPane().add(jLabel8, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 221, -1, -1));

        jLabel9.setText("C.P");
        getContentPane().add(jLabel9, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 259, -1, -1));

        txtID.setEditable(false);
        txtID.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtIDActionPerformed(evt);
            }
        });
        getContentPane().add(txtID, new org.netbeans.lib.awtextra.AbsoluteConstraints(95, 10, 150, -1));

        txtApellido.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtApellidoActionPerformed(evt);
            }
        });
        getContentPane().add(txtApellido, new org.netbeans.lib.awtextra.AbsoluteConstraints(95, 70, 150, -1));

        txtPreCel.setEditable(false);
        txtPreCel.setText("15");
        getContentPane().add(txtPreCel, new org.netbeans.lib.awtextra.AbsoluteConstraints(95, 130, 40, -1));
        getContentPane().add(txtLocalidad, new org.netbeans.lib.awtextra.AbsoluteConstraints(95, 160, 150, -1));
        getContentPane().add(txtCalle, new org.netbeans.lib.awtextra.AbsoluteConstraints(95, 190, 150, -1));
        getContentPane().add(txtNumCalle, new org.netbeans.lib.awtextra.AbsoluteConstraints(95, 220, 150, -1));

        txtCP.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtCPActionPerformed(evt);
            }
        });
        getContentPane().add(txtCP, new org.netbeans.lib.awtextra.AbsoluteConstraints(95, 250, 150, -1));

        BtnAceptar.setText("Aceptar");
        BtnAceptar.setPreferredSize(new java.awt.Dimension(80, 23));
        BtnAceptar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BtnAceptarActionPerformed(evt);
            }
        });
        getContentPane().add(BtnAceptar, new org.netbeans.lib.awtextra.AbsoluteConstraints(50, 330, -1, -1));

        BtnCancelar.setText("Cancelar");
        BtnCancelar.setMaximumSize(new java.awt.Dimension(80, 23));
        BtnCancelar.setPreferredSize(new java.awt.Dimension(80, 23));
        BtnCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BtnCancelarActionPerformed(evt);
            }
        });
        getContentPane().add(BtnCancelar, new org.netbeans.lib.awtextra.AbsoluteConstraints(160, 330, -1, -1));
        getContentPane().add(txtCel, new org.netbeans.lib.awtextra.AbsoluteConstraints(140, 130, 104, -1));

        txtTel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtTelActionPerformed(evt);
            }
        });
        getContentPane().add(txtTel, new org.netbeans.lib.awtextra.AbsoluteConstraints(95, 100, 150, -1));

        jLabel10.setText("Piso");
        getContentPane().add(jLabel10, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 290, -1, -1));

        txtPiso.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtPisoActionPerformed(evt);
            }
        });
        getContentPane().add(txtPiso, new org.netbeans.lib.awtextra.AbsoluteConstraints(95, 280, 150, -1));
        getContentPane().add(txtNombre, new org.netbeans.lib.awtextra.AbsoluteConstraints(95, 40, 150, -1));
    }// </editor-fold>//GEN-END:initComponents

    private void txtIDActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtIDActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtIDActionPerformed

    private void txtApellidoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtApellidoActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtApellidoActionPerformed

    private void txtCPActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtCPActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtCPActionPerformed
    
    private void BtnAceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BtnAceptarActionPerformed
        Integer cod=this.cliente.getNroCliente();
        admCliente.updateNombreDelCliente(cod, txtNombre.getText());
        admCliente.updateApellidoDelCliente(cod, txtApellido.getText());
        admCliente.updateTelDelCliente(cod, txtTel.getText());
        admCliente.updateCelDelCliente(cod, txtCel.getText());
        admCliente.updateCalleDelCliente(cod, txtCalle.getText());
        admCliente.updateLocalidadDelCliente(cod, txtLocalidad.getText());
        admCliente.updateCPDelCliente(cod, txtCP.getText());
        admCliente.updateNroCalleDelCliente(cod, txtNumCalle.getText());
        admCliente.updatePisoDelCliente(cod, txtPiso.getText());
        this.dispose();
    }//GEN-LAST:event_BtnAceptarActionPerformed

    private void BtnCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BtnCancelarActionPerformed

        this.dispose();
   /*     BuscarCliente buscarCliente = new BuscarCliente(null, rootPaneCheckingEnabled);
        buscarCliente.setVisible(false);*/
    }//GEN-LAST:event_BtnCancelarActionPerformed

    private void txtTelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtTelActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtTelActionPerformed

    private void txtPisoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtPisoActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtPisoActionPerformed

    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(VentanaPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(VentanaPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(VentanaPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(VentanaPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the dialog */
/*        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                ModificacionCliente dialog = null;
                try {
                    dialog = new ModificacionCliente(new javax.swing.JFrame(), true,liente);
                } catch (SQLException ex) {
                    Logger.getLogger(ModificacionCliente.class.getName()).log(Level.SEVERE, null, ex);
                }
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });*/
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton BtnAceptar;
    private javax.swing.JButton BtnCancelar;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    protected javax.swing.JTextField txtApellido;
    private javax.swing.JTextField txtCP;
    private javax.swing.JTextField txtCalle;
    private javax.swing.JTextField txtCel;
    protected final javax.swing.JTextField txtID = new javax.swing.JTextField();
    private javax.swing.JTextField txtLocalidad;
    private javax.swing.JTextField txtNombre;
    private javax.swing.JTextField txtNumCalle;
    private javax.swing.JTextField txtPiso;
    private javax.swing.JTextField txtPreCel;
    private javax.swing.JTextField txtTel;
    // End of variables declaration//GEN-END:variables
}


